package contact.controller;

import java.util.List;

import model.db.Annotation;



import org.hibernate.HibernateException;
import org.hibernate.Session;

import contact.util.HibernateUtil;

public class AssesmentManager {

public Annotation add(Annotation annotation) {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(annotation);
		session.getTransaction().commit();
		return annotation;
	}
	
	public Annotation delete(Long id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Annotation ann = (Annotation) session.load(Annotation.class, id);
		if(null != ann) {
			session.delete(ann);
		}
		session.getTransaction().commit();
		return ann;
	}
	
	
	public List<Annotation> list() {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Annotation> queries = null;
		
		try {
			
			queries = (List<Annotation>)session.createQuery("from Annotation").list();
			
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return queries;
	}
	
	
	
}
